package com.ktjiaotu;

import com.ktjiaotu.pojo.Person;

import java.lang.reflect.Modifier;

/**
 * @Author: DABINGCHNEGJIAO
 * @CreateTime: 2025-06-03
 * @Description:
 * @Version: 1.0
 */
public class GetClassInfo {
    public static void main(String[] args) {
        Class clazz = Person.class;
        String name = clazz.getName();
        String simpleName = clazz.getSimpleName();
        System.out.println("以下是"+name+"的信息");
        System.out.println("*--------------------------*");

        Package aPackage = clazz.getPackage();  //获取包类
        System.out.println(simpleName+"所在的包是："+aPackage.getName());
        System.out.println("-----------------------------");

        Class superclass = clazz.getSuperclass();
        System.out.println(simpleName+"的父类是"+superclass.getName());
        System.out.println("----------------------------");

        Class[] interfaces = clazz.getInterfaces();
        for (Class i : interfaces) {
            System.out.println(simpleName+"实现的接口有"+i.getName());
        }
        System.out.println("----------------------------");
        int modifiers = clazz.getModifiers();
        System.out.println(simpleName+"类的修饰符:");
        if ((modifiers & Modifier.PUBLIC) == Modifier.PUBLIC) {
            System.out.println(simpleName+"访问修饰符是:public");
        }else
            System.out.println("访问修饰符是 default(package)");
        if ((modifiers & Modifier.FINAL) == Modifier.FINAL) {
            System.out.println("这个类是 final的");
        }
        if ((modifiers & Modifier.ABSTRACT) == Modifier.ABSTRACT) {
            System.out.println("这个类是 abstract的");
        }
        if ((modifiers & Modifier.INTERFACE) == Modifier.INTERFACE) {
            System.out.println("这是一个接口");
        }
    }
}
